package com.huawei.hwid.usecase;

import android.content.Context;
import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcelable.Creator;
import android.text.TextUtils;
import com.huawei.cloudservice.CloudRequestHandler;
import com.huawei.hwid.UseCase;
import com.huawei.hwid.core.b.a.a.b;
import com.huawei.hwid.core.b.a.a.f;
import com.huawei.hwid.core.d.b.e;
import com.huawei.hwid.core.datatype.HwAccount;
import com.huawei.hwid.core.helper.handler.ErrorStatus;

public class GetUserInfoUseCase extends UseCase<RequestValues> {
    private Context a;
    private HwAccount b;
    private CloudRequestHandler c;

    public static final class RequestValues extends com.huawei.hwid.UseCase.RequestValues {
        public static final Creator<RequestValues> CREATOR = new Creator<RequestValues>() {
            public /* synthetic */ Object createFromParcel(Parcel parcel) {
                return a(parcel);
            }

            public /* synthetic */ Object[] newArray(int i) {
                return a(i);
            }

            public RequestValues a(Parcel parcel) {
                return new RequestValues(parcel);
            }

            public RequestValues[] a(int i) {
                return new RequestValues[i];
            }
        };
        private String a;

        public RequestValues(String str) {
            this.a = str;
        }

        protected RequestValues(Parcel parcel) {
            this.a = parcel.readString();
        }

        public int describeContents() {
            return 0;
        }

        public void writeToParcel(Parcel parcel, int i) {
            parcel.writeString(this.a);
        }
    }

    class a implements CloudRequestHandler {
        final /* synthetic */ GetUserInfoUseCase a;

        private a(GetUserInfoUseCase getUserInfoUseCase) {
            this.a = getUserInfoUseCase;
        }

        public void onFinish(Bundle bundle) {
            this.a.e();
        }

        public void onError(ErrorStatus errorStatus) {
            if (errorStatus != null) {
                e.b("GetUserInfoUseCase", "sterror.code ", true);
                if (errorStatus.getErrorCode() == 70002016 || errorStatus.getErrorCode() == 70002015) {
                    this.a.c.onError(new ErrorStatus(4099, "token invalid"));
                } else {
                    this.a.c.onError(errorStatus);
                }
            }
        }
    }

    public /* synthetic */ void b(com.huawei.hwid.UseCase.RequestValues requestValues) {
        a((RequestValues) requestValues);
    }

    public GetUserInfoUseCase(Context context, HwAccount hwAccount, CloudRequestHandler cloudRequestHandler) {
        this.a = context;
        this.b = hwAccount;
        this.c = cloudRequestHandler;
    }

    protected void a(RequestValues requestValues) {
        e.b("GetUserInfoUseCase", "GetUserInfoUseCase", true);
        if (this.b == null) {
            e.b("GetUserInfoUseCase", "mHwAccount is null", true);
        } else if (TextUtils.isEmpty(com.huawei.hwid.d.a.a(this.a).a(this.b.d()))) {
            e.b("GetUserInfoUseCase", "memery has no cookie,need stauth", true);
            d();
        } else {
            e();
        }
    }

    private void d() {
        com.huawei.hwid.core.b.a.a fVar = new f(this.a, this.b.c(), this.b.g(), this.b.e(), this.b.i(), this.b.k());
        fVar.a(this.a, fVar, this.b.b(), new a());
    }

    private void e() {
        com.huawei.hwid.core.b.a.a bVar = new b(this.a, this.b.d(), ((RequestValues) a()).a, null);
        bVar.a(this.a, bVar, this.b.b(), this.c);
    }
}
